﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace xCarLinkMP3Organizer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static MainWindow Instance;

        private readonly ViewModel _vm;

        public MainWindow()
        {
            InitializeComponent();

            _vm = new ViewModel();
            DataContext = _vm;
            Instance = this;

            Application.Current.Activated += OnApplicationActivated;
        }

        private void OnApplicationActivated(object sender, EventArgs e)
        {
            if (_vm.WinampActive != null)
                _vm.WinampActive.CheckWinampActive();
        }

        protected override void OnActivated(EventArgs e)
        {
            base.OnActivated(e);

            if (_vm.WinampActive != null)
                _vm.WinampActive.CheckWinampActive();
        }
    }

    public class DiscDataTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var t = item.GetType();

            if (typeof(DiscViewModel).IsAssignableFrom(item.GetType()))
            {
                return (DataTemplate) ((FrameworkElement) container).FindResource("DvmTemplate");
            }
            else if (typeof(FakeDiscViewModel).IsAssignableFrom(item.GetType()))
            {
                return (DataTemplate)((FrameworkElement)container).FindResource("FakeTemplate");
            }
            return null;
        }
    }
}